package com.zhiyou100.xml.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class Demo4 {

    public static void main(String[] args) throws IOException {

        String path = Demo4.class.getClassLoader().getResource("test.xml").getPath();
        Document document = Jsoup.parse(new File(path), "UTF-8");
        //选择器
        //# id选择器
        Elements elements = document.select("#001");
        System.out.println(elements.text());
        //标签选择器
        Elements elements1 = document.select("user");
        System.out.println(elements1.text());
        //根据标签的name获取
        Elements elements2 = document.select("user[name='user1']");
        System.out.println("elements2.text() = " + elements2.text());
        //获取name=user2标签的gender子标签    >
        Elements elements3 = document.select("user[name='user2']>gender");
        System.out.println("elements3.text() = " + elements3.text());




    }


}
